<?php
namespace app\index\controller;
header("Access-Control-Allow-Origin: *");
header("Access-Control-Allow-Methods:POST,GET");

use app\common\controller\HomeBase;
use think\Db;

class Homepage extends HomeBase
{
	protected function _initialize(){
		parent::_initialize();
	}

	/**
	*app首页   
	**/
	public function index()
	{
		$list['showPhoto'] = $this->showPhoto();
		$list['nav'] = $this->nav();
		$list['shopList'] = $this->shopList();
		if($list){
            $this->apiSuccess($list);
        }else{
            $this->apiError('没有查到信息');
        }
	}

	/**
    *轮播图
    **/
    public function showPhoto($id=1)
    {
        $showPhoto = Db('slide')->where('cid',$id)->select();
        return $showPhoto;
    }

    /**
    *获取栏目
    **/
	public function nav()
	{
		$navList = Db('nav')->where('pid',0)->select();
		return $navList;
	}

	/**
    *获取商品信息
    **/
    public function shopList()
    {
    	$shopList = Db('store_truck')->where('is_recommend',1)->page(1,3)->select();
        $i = 0;
        for(;$i<count($shopList);$i++){
            $shopList[$i]['photo'] = unserialize($shopList[$i]['photo']);
        }
    	return $shopList;
    }

}